package com.hujie.sqlqueryes.controller;

import com.hujie.sqlqueryes.dto.SqlQueryDTO;
import com.hujie.sqlqueryes.dto.DslResultDTO;
import com.hujie.sqlqueryes.service.SqlToDslConverterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
@CrossOrigin(origins = "*")
public class SqlToDslController {
    
    @Autowired
    private SqlToDslConverterService sqlToDslConverterService;
    
    @PostMapping("/sql/to-dsl")
    public DslResultDTO convertToDsl(@RequestBody SqlQueryDTO sqlQuery) {
        if (sqlQuery.getSql() == null || sqlQuery.getSql().trim().isEmpty()) {
            return DslResultDTO.error("SQL语句不能为空");
        }
        
        return sqlToDslConverterService.convertSqlToDsl(sqlQuery.getSql());
    }
}